from rest_framework.fields import SerializerMethodField
from rest_framework.serializers import ModelSerializer

from search.models import Record, Car


class CarSerializer(ModelSerializer):

    class Meta:
        model = Car
        fields = ('carno', 'owner')


class RecordSerializer(ModelSerializer):
    car = SerializerMethodField()
    makedate = SerializerMethodField()

    @staticmethod
    def get_car(record):
        return CarSerializer(record.car).data

    @staticmethod
    def get_makedate(record):
        return record.makedate.strftime('%Y年%m月%d日')

    class Meta:
        model = Record
        exclude = ('is_deleted', 'deleted_time', 'updated_time')
